home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9953 < prev    next >
Encoding:
Text File  |  1996-08-05  |  902 b   |  35 lines

  1. Path: cs.tu-berlin.de!news
  2. From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Forced override?
  5. Date: Tue, 05 Mar 1996 10:49:19 +0100
  6. Organization: Technical University of Berlin
  7. Message-ID: <313C0E1F.1FDE@cs.tu-berlin.de>
  8. References: <m1ybpgkvpa.fsf@zoger.ipost.com>
  9. NNTP-Posting-Host: 130.149.17.230
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win95; I)
  14.  
  15. Bob Glickstein wrote:
  16. > Quick question: is it possible to declare a virtual member function in
  17. > such a way that derived classes are *required* to override it?  This
  18. > would have to work for classes both directly and indirectly derived.
  19. > Thanks in advance.
  20.  
  21. You have to declare a pure virtual function, e. g.:
  22.  
  23. class A
  24. {
  25.  virtual void foo() = 0;
  26. };
  27.  
  28. Derived classes can only be instantiated if the foo is overridden.
  29.  
  30. Bye
  31.  
  32. Roman
  33.